package com.example.lets;

import com.bmob.BTPFileResponse;
import com.bmob.BmobPro;
import com.bmob.BmobProFile;
import com.bmob.btp.callback.DownloadListener;
import com.bmob.btp.callback.LocalThumbnailListener;
import com.gc.materialdesign.views.ButtonFloat;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;
import com.widget.CircleImageView;

import android.app.usage.UsageEvents;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.datatype.BmobQueryResult;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.GetListener;
import cn.bmob.v3.listener.SQLQueryListener;
import cn.bmob.v3.listener.SaveListener;


import android.annotation.TargetApi;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;

public class EventActivity extends BaseActivity implements ObservableScrollViewCallbacks {

	private static final float MAX_TEXT_SCALE_DELTA = 0.3f;

	private ImageView mImageView;
	private View mOverlayView;
	private View mListBackgroundView;
	private TextView mTitleView;
	private View mFab;
	private ObservableListView listView;
	private ArrayList<HashMap<String, Object>> listItem;
	private CommentAdapter adapter;
	private int mActionBarSize;
	private int mFlexibleSpaceShowFabOffset;
	private int mFlexibleSpaceImageHeight;
	private int mFabMargin;
	private boolean mFabIsShown;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event);

		mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
		mFlexibleSpaceShowFabOffset = getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
		mActionBarSize = getActionBarSize();
		mImageView = (ImageView) findViewById(R.id.type_image);
		mOverlayView = findViewById(R.id.overlay);
		listView = (ObservableListView) findViewById(R.id.list);
		listView.setScrollViewCallbacks(this);

		// Set padding view for ListView. This is the flexible space.
		View paddingView = new View(this);
		AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
				mFlexibleSpaceImageHeight);
		paddingView.setLayoutParams(lp);

		// This is required to disable header's list selector effect
		paddingView.setClickable(true);

		listView.addHeaderView(paddingView);
		mTitleView = (TextView) findViewById(R.id.title);
		mTitleView.setText(getTitle());
		setTitle(null);
		mFab = findViewById(R.id.fab);
		//mFab.setOnClickListener(new View.OnClickListener() {
		//	@Override
		//	public void onClick(View v) {
		//		Toast.makeText(EventActivity.this, "FAB is clicked", Toast.LENGTH_SHORT).show();
		//	}
		//});
		mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
		ViewHelper.setScaleX(mFab, 0);
		ViewHelper.setScaleY(mFab, 0);

		// mListBackgroundView makes ListView's background except header view.
		mListBackgroundView = findViewById(R.id.list_background);

		// load event header
		LayoutInflater inflater = getLayoutInflater();
		View eventHeader = inflater.inflate(R.layout.event_header, null);
		listView.addHeaderView(eventHeader);

		// original codes starts here
		final Intent in = getIntent();
		String title = in.getStringExtra("title");
		String description = in.getStringExtra("description");
		String PicfileName = in.getStringExtra("picFileName");
		final String sponsorId = in.getStringExtra("sponsorId");
		final String type = in.getStringExtra("type");
		final String ActiId = in.getStringExtra("id");

		loadComments(ActiId);

		TextView vDescription = (TextView) eventHeader.findViewById(R.id.event_full_info_description);
		vDescription.setHint("");
		vDescription.setText(description);

		// 返回导航键
		ImageView backButton = (ImageView) findViewById(R.id.back_button);
		backButton.bringToFront();
		backButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				EventActivity.this.finish();
			}
		});

		// Float button
		ButtonFloat joinButton = (ButtonFloat) mFab;
		joinButton.setRippleSpeed(10.0f);
		// set icon
		ImageView imageView = new ImageView(EventActivity.this);
		Drawable drawable = getResources().getDrawable(R.drawable.initiate_event_button);
		imageView.setImageDrawable(drawable);
		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		imageView.setLayoutParams(params);
		joinButton.addView(imageView);
		joinButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				User curUser = BmobUser.getCurrentUser(EventActivity.this, User.class);
				final String userId = curUser.getObjectId();

				BmobQuery<Involvement> query = new BmobQuery<Involvement>();
				query.addWhereEqualTo("activityId", ActiId);
				query.addWhereEqualTo("userId", userId);
				query.setLimit(100);
				query.findObjects(EventActivity.this, new FindListener<Involvement>() {
					@Override
					public void onSuccess(List<Involvement> list) {
						if (list.size() > 0) {
							Toast.makeText(EventActivity.this, "您已经加入该活动", Toast.LENGTH_SHORT).show();
							Log.i("bmob", "加入活动失败！");
						} else {
							Involvement record = new Involvement();
							record.setActivityId(ActiId);
							record.setSponsorId(sponsorId);
							record.setUserId(userId);
							record.save(EventActivity.this, new SaveListener() {

								@Override
								public void onSuccess() {
									// TODO Auto-generated method stub
									BmobQuery<UserActivity> q = new BmobQuery<UserActivity>();
									q.getObject(EventActivity.this, ActiId, new GetListener<UserActivity>() {

										@Override
										public void onSuccess(UserActivity userActivity) {
											userActivity.increment("peopleNumber", 1);
											userActivity.update(EventActivity.this);
											Toast.makeText(EventActivity.this, "活动加入成功！", Toast.LENGTH_SHORT).show();
											Log.i("bmob", "加入活动成功！");
											Intent intent = new Intent();
											intent.setClass(EventActivity.this, HomeActivity.class);
											startActivity(intent);
											EventActivity.this.finish();
										}

										@Override
										public void onFailure(int i, String s) {
											Toast.makeText(EventActivity.this, "加入活动失败！", Toast.LENGTH_SHORT).show();
											Log.i("bmob", "加入活动失败！");
										}
									});
								}

								@Override
								public void onFailure(int arg0, String arg1) {
									// TODO Auto-generated method stub
									Toast.makeText(EventActivity.this, "加入活动失败！", Toast.LENGTH_SHORT).show();
									Log.i("bmob", "加入活动失败！");
								}
							});
						}
					}

					@Override
					public void onError(int i, String s) {

					}
				});
			}
		});

		final ImageView photo = (ImageView) eventHeader.findViewById(R.id.event_full_info_img);

		final TextView sponsor = (TextView) eventHeader.findViewById(R.id.event_full_info_sponsor);
		String id = in.getStringExtra("sponsorId");
		BmobQuery<User> q = new BmobQuery<User>();
		q.addWhereEqualTo("objectId", id);
		q.findObjects(EventActivity.this, new FindListener<User>() {

			@Override
			public void onError(int arg0, String arg1) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSuccess(List<User> result) {
				// TODO Auto-generated method stub
				String sponsorName = result.get(0).getNickname();
				sponsor.setText(sponsorName);
			}

		});

		if (type.equals("food")) {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.food_event);
			mImageView.setImageDrawable(imgDrawable);
		} else if (type.equals("sport")) {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.sport_event);
			mImageView.setImageDrawable(imgDrawable);
		} else if (type.equals("tour")) {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.trip_event);
			mImageView.setImageDrawable(imgDrawable);
		} else if (type.equals("game")) {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.game_event);
			mImageView.setImageDrawable(imgDrawable);
		} else if (type.equals("study")) {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.study_event);
			mImageView.setImageDrawable(imgDrawable);
		} else {
			Drawable imgDrawable = getResources().getDrawable(R.drawable.movie_event);
			mImageView.setImageDrawable(imgDrawable);
		}

		TextView time = (TextView) eventHeader.findViewById(R.id.event_full_info_date);
		time.setText(in.getStringExtra("time"));

		TextView place = (TextView) eventHeader.findViewById(R.id.event_full_info_place);
		place.setText(in.getStringExtra("place"));

		//這部分來自TabActivity里面
		final Context context = EventActivity.this;

		String cachePath = BmobPro.getInstance(context).getCacheDownloadDir() + "/" + PicfileName;

		if ((new File(cachePath)).exists()) { // 缓存存在直接加载

			Log.i("bmob", "成功加载缓存：" + cachePath);
			Bitmap bm = BitmapFactory.decodeFile(cachePath);
			photo.setImageBitmap(bm);
			String str = BmobPro.getInstance(context).getCacheDownloadDir();
			Log.i("bmob", str);

		} else { // 缓存不存在需要从远程下载

			BTPFileResponse response = BmobProFile.getInstance(context).download(PicfileName, new DownloadListener() {

				@Override
				public void onSuccess(String fullPath) {
					// TODO Auto-generated method stub
					Log.i("bmob", "下载成功：" + fullPath);
					Bitmap bm = BitmapFactory.decodeFile(fullPath);
					photo.setImageBitmap(bm);
					String str = BmobPro.getInstance(context).getCacheDownloadDir();
					Log.i("bmob", str);
				}

				@Override
				public void onProgress(String localPath, int percent) {
					// TODO Auto-generated method stub
					Log.i("bmob", "download-->onProgress :" + percent);
				}

				@Override
				public void onError(int statuscode, String errormsg) {
					// TODO Auto-generated method stub
					Log.i("bmob", "下载出错：" + statuscode + "--" + errormsg);
					Toast.makeText(context, "下载出错："+ statuscode + "--" + errormsg, Toast.LENGTH_SHORT).show();
				}
			});
		}

		// 此处开始查询已加入的用户
		final LinearLayout userList = (LinearLayout) eventHeader.findViewById(R.id.event_user_list);
		BmobQuery<Involvement> bmobQuery = new BmobQuery<Involvement>();
		bmobQuery.addWhereEqualTo("activityId", in.getStringExtra("id"));
		bmobQuery.addQueryKeys("userId");
		bmobQuery.setLimit(10);
		bmobQuery.findObjects(this, new FindListener<Involvement>() {
			@Override
			public void onSuccess(List<Involvement> object) {
				// TODO Auto-generated method stub
				Toast.makeText(EventActivity.this, "共" + object.size() + "人", Toast.LENGTH_SHORT);
				//注意：这里的Involvement对象中只有指定列的数据。
				for (Involvement inv : object) {
					String userId = inv.getUserId();
					BmobQuery<User> bmobQuery = new BmobQuery<User>();
					bmobQuery.addQueryKeys("nickname,picFileName");
					bmobQuery.getObject(EventActivity.this, userId, new GetListener<User>() {

						@Override
						public void onFailure(int i, String s) {
							// TODO: 2015/11/8
						}

						@Override
						public void onSuccess(User user) {
							LayoutInflater inflater = LayoutInflater.from(EventActivity.this);
							View singleUser = inflater.inflate(R.layout.listview_user_simple, null);
							TextView userName = (TextView) singleUser.findViewById(R.id.user_simple_name);
							final CircleImageView userImage = (CircleImageView) singleUser.findViewById(R.id.user_simple_img);
							userName.setText(user.getNickname());

							// 获取头像文件名
							String fileName = user.getPicFilename();

							// 得到文件路径
							User curUser = BmobUser.getCurrentUser(context, User.class);
							String cacheDownloadPath = BmobPro.getInstance(context).getCacheDownloadDir() + "/" + fileName;
							String[] name = fileName.split("\\.");
							String newFileName = name[0] + "_1_200_0_100." + name[1];
							String cacheThumbnailPath = BmobPro.getInstance(context).getCacheThumbnailDir() + "/" + newFileName;

							if ((new File(cacheDownloadPath)).exists()) { // 判断是否存在文件

								if ((new File(cacheThumbnailPath)).exists()) { // 判断是否存在缓存

									//Log.i("bmob", "?????????棺" + cacheThumbnailPath);
									Bitmap bm = BitmapFactory.decodeFile(cacheThumbnailPath);
									userImage.setImageBitmap(bm);

								} else { // 缓存不存在则重新生成缓存

									BmobProFile.getInstance(context).getLocalThumbnail(cacheDownloadPath, 1, new LocalThumbnailListener() {

										@Override
										public void onSuccess(String thumbnailPath) {
											//Log.i("bmob", "localThumbnail-->???????????·?? :" + thumbnailPath);
											Bitmap bm = BitmapFactory.decodeFile(thumbnailPath);
											userImage.setImageBitmap(bm);
										}

										@Override
										public void onError(int statuscode, String errormsg) {
											//Log.i("bmob", "localThumbnail-->???????????? :" + statuscode + "," + errormsg);
										}
									});

								}

							} else { // 文件不存在需要重新下载

								BmobProFile.getInstance(context).download(fileName, new DownloadListener() {

									@Override
									public void onSuccess(String fullPath) {
										Log.i("bmob", "????????" + fullPath);
										// ?????????????????????????
										BmobProFile.getInstance(context).getLocalThumbnail(fullPath, 1, new LocalThumbnailListener() {

											@Override
											public void onSuccess(String thumbnailPath) {
												Log.i("bmob", "localThumbnail-->???????????·?? :" + thumbnailPath);
												Bitmap bm = BitmapFactory.decodeFile(thumbnailPath);
												userImage.setImageBitmap(bm);
											}

											@Override
											public void onError(int statuscode, String errormsg) {
												Log.i("bmob", "localThumbnail-->???????????? :" + statuscode + "," + errormsg);
											}
										});
										String str = BmobPro.getInstance(context).getCacheDownloadDir();
										Log.i("bmob", str);
									}

									@Override
									public void onProgress(String localPath, int percent) {
										Log.i("bmob", "download-->onProgress :" + percent);
									}

									@Override
									public void onError(int statuscode, String errormsg) {
										Log.i("bmob", "???????" + statuscode + "--" + errormsg);

									}
								});
							}
							userList.addView(singleUser);
						}
					});
				}
			}

			@Override
			public void onError(int code, String msg) {
				// TODO Auto-generated method stub
				Toast.makeText(EventActivity.this, "查询失败", Toast.LENGTH_SHORT);
			}
		});

	}

	private void loadComments(String id) {

		BmobQuery<Comment> query = new BmobQuery<Comment>();
		query.addWhereEqualTo("activityId", id);
		query.setLimit(100);
		query.include("user");

		query.findObjects(this, new FindListener<Comment>() {

			@Override
			public void onSuccess(List<Comment> object) {
				listItem = new ArrayList<HashMap<String, Object>>();

				for (Comment comment : object) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					map.put("CommentContent", comment.getContent());
					map.put("CommentDate", comment.getCreatedAt());
					map.put("UserName", comment.getUser().getNickname());
					map.put("UserImageName", comment.getUser().getPicFilename());
					listItem.add(map);
				}

				adapter = new CommentAdapter(EventActivity.this, listItem);
				listView.setAdapter(adapter);
			}

			@Override
			public void onError(int code, String msg) {
				Toast.makeText(EventActivity.this, "下载失败，网络异常！", Toast.LENGTH_SHORT).show();
			}
		});
	}

	class CommentAdapter extends BaseAdapter {

		private LayoutInflater mInflater;
		private ArrayList<HashMap<String, Object>> list;
		private Context context;

		public CommentAdapter(Context context, ArrayList<HashMap<String, Object>> list) {
			this.mInflater = LayoutInflater.from(context);
			this.list = list;
			this.context = context;
		}

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {

			final CommentViewHolder holder;
			Log.v("MyListViewBase", "getView " + position + " " + convertView);
			if (convertView == null) {

				convertView = mInflater.inflate(R.layout.comment_card, null);
				holder = new CommentViewHolder();

				holder.content = (TextView)        convertView.findViewById(R.id.comment_content);
				holder.user    = (TextView)        convertView.findViewById(R.id.user_name);
				holder.date    = (TextView)        convertView.findViewById(R.id.comment_date);
				holder.image   = (CircleImageView) convertView.findViewById(R.id.user_image);

				convertView.setTag(holder);
			}
			else{
				holder = (CommentViewHolder)convertView.getTag();
			}

			holder.content.setText(list.get(position).get("CommentContent").toString());
			holder.user.setText(list.get(position).get("UserName").toString());
			holder.date.setText(list.get(position).get("CommentDate").toString());

			String fileName = (String) list.get(position).get("UserImageName");
			String cacheDownloadPath = BmobPro.getInstance(context).getCacheDownloadDir() + "/" + fileName;
			String[] name = fileName.split("\\.");
			String newFileName = name[0] + "_1_200_0_100." + name[1];
			String cacheThumbnailPath = BmobPro.getInstance(context).getCacheThumbnailDir() + "/" + newFileName;

			if ((new File(cacheDownloadPath)).exists()) {

				if ((new File(cacheThumbnailPath)).exists()) {

					Bitmap bm = BitmapFactory.decodeFile(cacheThumbnailPath);
					holder.image.setImageBitmap(bm);

				} else {

					BmobProFile.getInstance(context).getLocalThumbnail(cacheDownloadPath, 1, new LocalThumbnailListener() {

						@Override
						public void onSuccess(String thumbnailPath) {
							Log.i("bmob", "localThumbnail--> :" + thumbnailPath);
							Bitmap bm = BitmapFactory.decodeFile(thumbnailPath);
							holder.image.setImageBitmap(bm);
						}

						@Override
						public void onError(int statuscode, String errormsg) {
							Log.i("bmob", "localThumbnail--> :" + statuscode + "," + errormsg);
						}
					});

				}

			} else { // ���治������Ҫ��Զ������

				BmobProFile.getInstance(context).download(fileName, new DownloadListener() {

					@Override
					public void onSuccess(String fullPath) {
						Log.i("bmob", "���سɹ���" + fullPath);
						// �������ص�ͼƬ�ڱ�����������ͼ
						BmobProFile.getInstance(context).getLocalThumbnail(fullPath, 1, new LocalThumbnailListener() {

							@Override
							public void onSuccess(String thumbnailPath) {
								Log.i("bmob", "localThumbnail-->���ɺ������ͼ·�� :" + thumbnailPath);
								Bitmap bm = BitmapFactory.decodeFile(thumbnailPath);
								holder.image.setImageBitmap(bm);
							}

							@Override
							public void onError(int statuscode, String errormsg) {
								Log.i("bmob", "localThumbnail-->��������ͼʧ�� :" + statuscode + "," + errormsg);
							}
						});
						String str = BmobPro.getInstance(context).getCacheDownloadDir();
						Log.i("bmob", str);
					}

					@Override
					public void onProgress(String localPath, int percent) {
						Log.i("bmob", "download-->onProgress :" + percent);
					}

					@Override
					public void onError(int statuscode, String errormsg) {
						Log.i("bmob", "���س���" + statuscode + "--" + errormsg);
						//Toast.makeText(context, "���س���"+ statuscode + "--" + errormsg, Toast.LENGTH_SHORT).show();
					}
				});
			}
			return convertView;
		}
	}

	@Override
	public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
		// Translate overlay and image
		float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
		int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
		ViewHelper.setTranslationY(mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
		ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

		// Translate list background
		ViewHelper.setTranslationY(mListBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight));

		// Change alpha of overlay
		ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

		// Scale title text
		float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
		setPivotXToTitle();
		ViewHelper.setPivotY(mTitleView, 0);
		ViewHelper.setScaleX(mTitleView, scale);
		ViewHelper.setScaleY(mTitleView, scale);

		// Translate title text
		int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
		int titleTranslationY = maxTitleTranslationY - scrollY;
		ViewHelper.setTranslationY(mTitleView, titleTranslationY);

		// Translate FAB
		int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
		float fabTranslationY = ScrollUtils.getFloat(
				-scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2,
				mActionBarSize - mFab.getHeight() / 2,
				maxFabTranslationY);
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
			// On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin,
			// which causes FAB's OnClickListener not working.
			FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams();
			lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth();
			lp.topMargin = (int) fabTranslationY;
			mFab.requestLayout();
		} else {
			ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
			ViewHelper.setTranslationY(mFab, fabTranslationY);
		}

		// Show/hide FAB
		if (fabTranslationY < mFlexibleSpaceShowFabOffset) {
			hideFab();
		} else {
			showFab();
		}
	}

	@Override
	public void onDownMotionEvent() {
	}

	@Override
	public void onUpOrCancelMotionEvent(ScrollState scrollState) {
	}

	@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
	private void setPivotXToTitle() {
		Configuration config = getResources().getConfiguration();
		if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
				&& config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
			ViewHelper.setPivotX(mTitleView, findViewById(android.R.id.content).getWidth());
		} else {
			ViewHelper.setPivotX(mTitleView, 0);
		}
	}

	private void showFab() {
		if (!mFabIsShown) {
			ViewPropertyAnimator.animate(mFab).cancel();
			ViewPropertyAnimator.animate(mFab).scaleX(1).scaleY(1).setDuration(200).start();
			mFabIsShown = true;
		}
	}

	private void hideFab() {
		if (mFabIsShown) {
			ViewPropertyAnimator.animate(mFab).cancel();
			ViewPropertyAnimator.animate(mFab).scaleX(0).scaleY(0).setDuration(200).start();
			mFabIsShown = false;
		}
	}
}

class CommentViewHolder {
	public CircleImageView image;
	public TextView content;
	public TextView date;
	public TextView user;
}
